package web;

import dao.impl.UserDaoImpl;
import pojo.User;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

public class SearchServlet extends HttpServlet {
              private UserService service =new UserServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String testbutton = request.getParameter("testbutton");

        if (service.searchUsername(testbutton)!=null){
            System.out.println("存在数据");
            List<User> userList=service.searchUsername(testbutton);
            request.setAttribute("userList",userList);
            request.getRequestDispatcher("/testjsp/Test.jsp").forward(request, response);
        }else {
            System.out.println("不存在数据");
            request.getRequestDispatcher("/testhtml/error.html").forward(request, response);
        }

    }
}
